#include "Position.h"
#include <cmath>

Position::Position(int x, int y)
        : x(x), y(y)
{
}

Position::Position()
        : x(0), y(0)
{
}

Position::~Position()
{
}

bool Position::operator==(const Position &other) const
{
    return (x == other.x) && (y == other.y);
}

bool Position::operator!=(const Position &other) const
{
    return !operator==(other);
}

Position Position::operator-() const
{
    return Position(-x, -y);
}

Position Position::operator +(const Position& other) const
{
    return Position(x + other.x, y + other.y);
}

Position Position::operator -(const Position& other) const
{
    return Position(x - other.x, y - other.y);
}

Position Position::move(const Position& delta) const
{
    return Position(x + delta.x, y + delta.y);
}

Position Position::scale(double factor) const
{
    return Position(floor(factor * x + 0.5), floor(factor * y + 0.5));
}

Position Position::rotateCWAround(const Position& origin) const
{
    return Position(-(y-origin.y), (x-origin.x)).move(origin);
}

Position Position::rotateCCWAround(const Position& origin) const
{
    return Position((y-origin.y), -(x-origin.x)).move(origin);
}
